<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<meta charset="UTF-8">
		<title>微站_共富网_Gofull.com.cn</title>
		<script src="/v3/js/jquery-1.10.2.min.js" type="text/javascript"></script>
		<link type="text/css" rel="stylesheet" href="/v3/css/wstyle.css">
		<link type="text/css" rel="stylesheet" href="/v3/css/account.css">
	</head>
	<body>
		<div id="wrap">
			<div class="input-box">
				<div class="login_input">
					<div class="r_line">
					<i class="icon-Code"></i>
					</div>
					<div class="in_put">
						<input id="mobile" name="mobile" type="hidden" value="${mobile}">
						<input placeholder="请输入动态码" id="captcha" name="captcha"
							maxlength="6" type=tel>
					</div>
				</div>
				<div class="login_input auth_code">
					<div class="r_line">
						<i class="icon-AuthCode"></i>
					</div>
					<div class="in_put">
						<input placeholder="请输入验证码" type="text" id="authCode" name="paramMap.code"
							onblur="chekVerifyCode()" class="input" style="width:65%" maxlength="4">
							<img src="I4008lOve893gOfUll983/imageCode.do?pageId=userregister"
								title="点击更换验证码" style="cursor: pointer;" id="imgverCode"
								onclick="switchCode('userregister');" width="104" alt="验证码"
								title="验证码" class="verifycode">
					</div>
				</div>
			</div>
			
			<div class="getPW" id="getPw"><a id="getAutoPwdBtn" href="javascript:getAutoPwd();">获取动态码</a></div>
			<div class="Nxt-btn"><a id="registerBtn" href="javascript:register();">确认</a></div>
			
		</div>
	</body>
<script type="text/javascript" src="/v3/js/showts.js"></script>
<script type="text/javascript">
$(function(){
switchCode('userregister');
});
function register() {
	//密码
	var $captcha = $('#captcha');
	var vCode = $("#authCode").val();
	//检验密码
	if ($captcha.val() == null || $captcha.val() == '') {
		showAlert('请输入动态码');
    	return;
	} else if (vCode == "" || vCode == null) {
			showAlert("请输入验证码");
			return;
	}else{

	var param = {};
	param["paramMap.pageId"] = "userregister";
	param["paramMap.authCode"] = $("#authCode").val();
	param["paramMap.mobile"] = $("#mobile").val();
	param["paramMap.captcha"] = $("#captcha").val();
	
	//异步请求
	$.ajax({
		type: 'POST',
		url: "/wchatRegister.do",
		data: param,
		beforeSend: function() {
            $("#registerBtn").attr("href","javascript:;").html("登录中...");
        },
		success: function(data) {
			if(data.code == 'registerFailed'){
				showAlert(data.msg);
				$("#registerBtn").attr("href","javascript:register();").html("确认");
			}else if(data.code == "errorCode"){
				showAlert(data.msg);
				$("#registerBtn").attr("href","javascript:register();").html("确认");
				return;
			}else{
				//登录成功，默认跳转至主页
				window.location.href = "/wchatIndex.do";
			}
		}
	});
	}
}

function getAutoPwd() {
	var vCode = $("#authCode").val();
	if (vCode == "" || vCode == null) {
			showAlert("请输入验证码");
			return;
	}
	if($("#getAutoPwdBtn").hasClass("disable-bt")){
		return;
	}

	var param = {};
    param["paramMap.pageId"] = "userregister";
	param["paramMap.mobile"] = $("#mobile").val();
	param["paramMap.authCode"] = $("#authCode").val();
	$.ajax({
		type: 'POST',
		url: "/getAutoPwd.do",
		data: param,
		success: function(data) {
			//错误等信息提示
			if(data.code == "failed"){
				showAlert(data.msg);
				return;
			}
			if(data.code == "errorCode"){
				showAlert(data.msg);
				switchCode('userregister');
				return;
			}
			//倒计时
			_interval = setInterval("autoPwdSend()", 1000);
		}
	});
}

/**
 * 60秒计时
 */
var n = 60;
/**
 * 连续执行方法句柄
 */
var _interval;
/**
 * 发送动态密码循环执行方法
 */
function autoPwdSend(){
	n--;
	//获取验证码按钮 不可用
	$("#getAutoPwdBtn").addClass("disable-bt");
    $("#getAutoPwdBtn").attr("href","javascript:;").html(n + "秒后可重发");
	
	if (n == 0) {
	    $("#getAutoPwdBtn").removeClass("disable-bt");
	    $("#getAutoPwdBtn").attr("href","javascript:getAutoPwd();").html("获取动态码");
		clearInterval(_interval);
		n = 60;
	}
}
	
function switchCode(str) {
	var timenow = new Date();
	$("#imgverCode").attr("src","I4008lOve893gOfUll983/imageCode.do?pageId="+str+"&d="+ timenow);
}				
</script>
</html>
